package com.hama.iotrust.common.mybatis.criteria;

import java.util.HashMap;
import java.util.Map;

import com.hama.iotrust.common.mybatis.criteria.Criteria;
import com.hama.iotrust.common.mybatis.criteria.CriteriaException;
import com.hama.iotrust.common.mybatis.criteria.Expression;

/**
 * IS NOT NULL 表达式条件
 * 
 * @author 金建强(ptma@163.com)
 * @version 1.0.0
 * @since 2012-3-15 下午05:52:09
 */
public class NotNullExpression implements Expression {

    private String m_propName;
    private String m_columnName = null;

    NotNullExpression(String propertyName){
        m_propName = propertyName;
    }

    public String getSql() {
        StringBuilder sb = new StringBuilder();
        sb.append("(");
        if (m_columnName == null) {
            sb.append("< not bound:").append(m_propName).append(">");
        } else {
            sb.append(m_columnName);
        }
        sb.append(" IS NOT NULL)");
        return sb.toString();
    }

    public Map<String, Object> getParameter() {
        Map<String, Object> map = new HashMap<String, Object>();
        return map;
    }

    public boolean verify(Criteria<?> criteria) {
        return criteria.hasProperty(m_propName);
    }

    public void bind(Criteria<?> crit) throws CriteriaException {
        m_columnName = crit.toColumnName(m_propName);
    }
}
